//package com.yby6.framework.filter;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.stereotype.Component;
//import com.yby6.common.config.YangBuYiConfig;
//import com.yby6.common.constant.Constants;
//import com.yby6.common.core.domain.ShiroSecurityUtils;
//import com.yby6.framework.shiro.config.ShiroProperties;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.util.Arrays;
//
///**
// * @program: yangbuyi-rbac
// * @ClassName: WebFilter
// * @create: 2021-05-12 10:34
// * @author: yangshuai
// * @since： JDK1.8
// * @WebFilter: web请求是否允许操作数据库$演示模式
// **/
//
//@Component
//@Slf4j
//public class WebFilter implements Filter {
//
//    @Autowired
//    private ShiroProperties shiroProperties;
//
//    @Override
//    public void doFilter (ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        if (YangBuYiConfig.isDemoEnabled()) {
//            HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//            String method = httpServletRequest.getMethod();
//            String url = httpServletRequest.getRequestURI();
//            String[] anonUrls = shiroProperties.getAnonUrls();
//            log.info("当前请求地址：{}", url.toString());
//            log.info("是否包含:{}", Arrays.binarySearch(anonUrls, url) > 0 || Arrays.asList(anonUrls).contains(url));
//            if (Arrays.binarySearch(anonUrls, url.toString()) > 0 || Arrays.asList(anonUrls).contains(url.toString())) {
//                filterChain.doFilter(servletRequest, servletResponse);
//            } else {
//                // 演示模式开启
//                if (Constants.POST.equalsIgnoreCase(method) || Constants.PUT.equalsIgnoreCase(method) || Constants.DELETE.equalsIgnoreCase(method)) {
//                    //将异常分发
//                    servletRequest.getRequestDispatcher("/demoModeException").forward(servletRequest, servletResponse);
//                } else {
//                    filterChain.doFilter(servletRequest, servletResponse);
//                }
//            }
//
//        } else {
//            filterChain.doFilter(servletRequest, servletResponse);
//        }
//    }
//}
